<template>
  <div class="blogpl">
    <div class="pl">
      <el-avatar :src="poot+'manongyizhanFile/users/'+user+'/头像/'+user+'.jpg'"></el-avatar>
      <el-input
        v-model="input"
        placeholder="请输入内容"
        maxlength="200"
        show-word-limit
        @keyup.enter.native="fabiaopinjia"
      ></el-input>
    </div>
    <div class="btu">
      <el-button size="mini" @click="fabiaopinjia">发表评价</el-button>
    </div>
    <div class="pldiv" v-for="(item,index2) in pl" :key="index2">
      <div class="f">
        <el-avatar
          :src="poot+'manongyizhanFile/users/'+item.comment.mailbox+'/头像/'+item.comment.mailbox+'.jpg'"
        ></el-avatar>
        <h3>{{item.comment.users}}</h3>
        <font>{{item.comment.time}}</font>
      </div>
      <div class="wenzi">{{item.comment.comment}}</div>
    </div>
  </div>
</template>
<script>
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";
export default {
  props: ["id"],
  data() {
    return {
      input: "",
      html: "",
      pl: [],
      username: "",
      length: 0
    };
  },
  methods: {
    pinglunjiazai() {
      this.$http
        .get(this.poot + "selectcommentByblogid/" + this.id)
        .then(response => {
          this.pl = response.data;
          console.log(this.pl);
          //向父组件传值
          this.$emit("func", this.pl.length);
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    fabiaopinjia() {
      if (this.input.length > 0) {
          this.$http
        .get(this.poot + "updateIntegral/" + this.id+"/"+this.user+"/"+5)
        .then(response => {})
        .catch(function(error) {
          console.log(error);
        });
        this.$http
          .post(this.poot + "insertcomment", {
            comment: this.input,
            mailbox: this.user,
            blogId: this.id
          })
          .then(response => {
            this.pinglunjiazai();
            this.input = "";
          })
          .catch(function(error) {
            console.log(error);
          });
      } else {
        this.open("你还没有输入内容", "warning");
      }
    },
    open(message, type) {
      this.$message({
        message: message,
        type: type
      });
    }
  },
  computed: {
    ...mapState(["leixing"]),
    ...mapState(["poot"]),
    ...mapState(["user"])
  },
  mounted() {
    this.pinglunjiazai();
  }
};
</script>
<style scoped>
.wenzi {
  margin-top: 20px;
}
h3 {
  margin-left: 30px;
  color: #354b7b;
  width: 200px;
}
.f {
  display: flex;
  align-items: center;
  margin-top: 20px;
}
.btu {
  text-align: right;
  margin-bottom: 20px;
}
.el-button {
  border: #ffd04b 2px solid;
  background-color: #1e1e1e;
  margin-top: 10px;
}
.el-input {
  margin-left: 20px;
}
.pl {
  display: flex;
}
.blogpl {
  margin-right: 20px;
}
</style>